import request from '@/utils/request'

// 1、条件查询用户分页列表
export const GetUserPage = (pageNum, pageSize, searchObj) => {
  return request({
    url: `/admin/system/user/list/${pageNum}/${pageSize}`,
    method: 'GET',
    // params/data/headers配置参数时 值必须是json对象
    params: searchObj, //url?keyword='xxxx'
  })
}
// 2、查询所有用户
export const GetUsers = () => {
  return request({
    url: `/admin/system/user/list`,
    method: 'GET',
  })
}
// 3、id查询用户
export const GetUserById = id => {
  return request({
    url: `/admin/system/user/getById/${id}`,
    method: 'GET',
  })
}
// 4、更新用户
export const UpdateUser = user => {
  return request({
    url: `/admin/system/user/update`,
    method: 'PUT',
    data: user,
  })
}
// 5、根据id删除用户
export const DeleteUser = id => {
  return request({
    url: `/admin/system/user/delete/${id}`,
    method: 'DELETE',
  })
}
// 6、新增用户
export const SaveUser = user => {
  return request({
    url: `/admin/system/user/save`,
    method: 'POST',
    data: user,
  })
}
// 7、给用户分配角色
export const AssignRoles2User = (id, roleIds) => {
  return request({
    url: `/admin/system/user/assignRoles2User/${id}`,
    method: 'PUT',
    // url?roleIds=1,2,3
    params: { roleIds: roleIds.join(',') },
    // data:roleIds
  })
}
